﻿using System;
using System.Collections.Generic;
using System.IO;
using RanbuOM.SSF4.BCM;
using RanbuOM.Serialization;

namespace RanbuCmd
{
    class Program
    {
        static void Main(string[] args)
        {
            //using (var reader = new RanbuReader(@"..\..\..\RanbuUT\TestData\RYU.obj.ema"))
            //{
            //    var ema = reader.Read<EmaFile>();
            //    DumpCoverageInfo(reader, @"..\..\..\emacov.txt");

            //    Console.WriteLine();
            //}
        }

        static void DumpBCM()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\GameData\SSF4AE_106_PC\regulation");
            var files = Directory.GetFiles(path, "*.bcm", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                using (var reader = new RanbuReader(file))
                {
                    var bcm = reader.ReadDataFile<BcmFile>();
                    var chara = file.Substring(file.Length - 7, 3);

                }
            }
        }


        //static void DumpCoverageInfo(RanbuReaderOld reader, string path)
        //{
        //    long head = 0;
        //    long totalMissing = 0;
        //    long totalOverlap = 0;
        //    var lines = new List<string>();
        //    foreach (var c in reader.Coverages.Values)
        //    {
        //        if (c.Start > head)
        //        {
        //            // overlap
        //            lines.Add(string.Format(
        //                "{0:X8}-{1:X8} MISSING : {2:X8} ({2}) bytes",
        //                head,
        //                c.Start,
        //                c.Start - head));
        //            totalMissing += c.Start - head;
        //        }
        //        else if (c.Start < head)
        //        {
        //            // overlap
        //            lines.Add(string.Format(
        //                "{0:X8}-{1:X8} OVERLAP : {2:X8} ({2}) bytes",
        //                c.Start,
        //                head,
        //                head - c.Start));
        //            totalOverlap += head - c.Start;
        //        }

        //        head = c.End;
        //        lines.Add(c.ToString());
        //    }

        //    if (head < reader.Length)
        //    {
        //        lines.Add(string.Format(
        //            "MISSING: {0:X8}-{1:X8} : {2:X8} ({2}) bytes",
        //            head,
        //            reader.Length,
        //            reader.Length - head));
        //        totalMissing += reader.Length - head;
        //    }

        //    lines.Add("");

        //    if (totalMissing == 0)
        //    {
        //        lines.Add("*** No missing found. ***");
        //    }
        //    else
        //    {
        //        lines.Add(string.Format("Total missed bytes: {0:X8} ({0}), {1}%", totalMissing, totalMissing * 100 / reader.Length));
        //    }

        //    if (totalOverlap == 0)
        //    {
        //        lines.Add("*** No overlap found. ***");
        //    }
        //    else
        //    {
        //        lines.Add(string.Format("Total overlapped bytes: {0:X8} ({0}), {1}%", totalOverlap, totalOverlap * 100 / reader.Length));
        //    }

        //    File.WriteAllLines(path, lines);
        //}
    }
}
